// role import
var roleHarvester = require('role.harvester');
var roleUpgrader = require('role.upgrader');
var roleConstructer = require('role.constructer')

// controler import
var commanderSource = require('commander.source');
var commanderuUserobj = require('commander.userobj');


module.exports.loop = function () {

    for (var name in Memory.creeps) {
        if (!Game.creeps[name]) {
            delete Memory.creeps[name];
            console.log('Clearing non-existing creep memory:', name);
        }
    }

    commanderuUserobj.run();
    for (let name in Game.rooms) {
        // mine commander
        var room = Game.rooms[name];
        commanderSource.run(room);
    }
    for (var name in Game.creeps) {
        // creep control
        var creep = Game.creeps[name];
        if (creep.memory.role == 'harvester') {
            roleHarvester.run(creep);
        }
        if (creep.memory.role == 'upgrader') {
            roleUpgrader.run(creep);
        }
        if (creep.memory.role == 'constructer') {
            roleConstructer.run(creep);
        }
        if (creep.memory.role == undefined) {
            creep.say('no role');
        }
    }
}